package com.frank.controller;


import com.frank.dto.CommonListDto;
import com.frank.dto.InterviewDto;
import com.frank.dto.JsonResult;
import com.frank.dto.QueryPageDto;
import com.frank.model.Interview;
import com.frank.service.InterviewManageService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/recruit")
public class InterviewManageController {
    @Resource
    private InterviewManageService interviewManageService;

    @RequestMapping(value = "/getInterviewList", method = RequestMethod.POST)
    public JsonResult<?> getInterviewList(@RequestBody QueryPageDto queryPageDto) {

        CommonListDto commonListDto = interviewManageService.getInterviewList(queryPageDto);

        return new JsonResult<>(200,"获得面试列表成功",commonListDto);

    }

    @Transactional
    @RequestMapping(value = "/addInterview", method = RequestMethod.POST)
    public JsonResult<?> addInterview(@RequestBody InterviewDto interviewDto) {
        if (interviewManageService.addInterview(interviewDto)){
            return new JsonResult<>(200,"新增面试成功");
        }else {
            return new JsonResult<>(500,"新增面试失败");
        }
    }

    @Transactional
    @RequestMapping(value = "/modifyInterview", method = RequestMethod.POST)
    public JsonResult<?> modifyInterview(@RequestBody Interview interview) {
        if (interviewManageService.modifyInterview(interview)){
            return new JsonResult<>(200,"修改面试成功");
        }else {
            return new JsonResult<>(500,"修改面试失败");
        }
    }

    @Transactional
    @RequestMapping(value = "/deleteInterview", method = RequestMethod.POST)
    public JsonResult<?> deleteInterview(@RequestParam("interviewId") Integer interviewId) {
        if (interviewManageService.deleteInterview(interviewId)){
            return new JsonResult<>(200,"删除面试成功");
        }else {
            return new JsonResult<>(500,"删除面试失败");
        }
    }

}
